package com.yaowk.sfp.utils.verification;

import java.util.Random;

/**
 * @author 小凯
 **/
public class CodeUtils {

    public static String createCode(int length) {
        byte[] bytes = new byte[length];
        for (int i = 0; i < length; i++) {
            bytes[i] = '0';
        }
        Integer nextInt = Integer.valueOf("1".concat(new String(bytes)));

        String res = String.valueOf(new Random().nextInt(nextInt));
        if (res.length() != length) {
            res = String.format("%" + length + "s", res);
            res = res.replaceAll("\\s", "0");
        }
        return res;
    }

    public static String createCode() {
        return createCode(6);
    }
}
